#include <iostream>
#include <vector>

#include "Locations.h"
#include "Sequence.h"
#include "Seeding.h"
#include "Neighboring.h"
#include "Assoc.h"
#include "Analysis.h"

using namespace std;

int main()
{

//    //values that should be filled in through argparse or a CLI
//    string spacer_loc = "/home/mikeshaffer/spacers.fna";
//    string contig_loc = "/home/mikeshaffer/contigs.fna";
//    string virus_dir = "/home/mikeshaffer/phages/";
//    string virus_fof = "/home/mikeshaffer/fof.txt";
//    char * results_c = "/home/mikeshaffer/results_c.txt";
//    char * results_g = "/home/mikeshaffer/results_g.txt";
//    char * cytoscape_c = "/home/mikeshaffer/edges_c.txt";
//    char * cytoscape_g = "/home/mikeshaffer/edges_g.txt";
//    char * PAMs_c = "/home/mikeshaffer/PAMs_c.txt";
//    char * PAMs_g = "/home/mikeshaffer/PAMs_g.txt";
//
//    int seed = 10;
//    float ident = .8;
//    bool check_genomes = false;

    //set up objects
    Locations * l = new Locations();
    Seeding * s = new Seeding(l->get_seed());
    Neighboring * n = new Neighboring(l->get_ident());
    Analysis * a = new Analysis();

    //get al spacers
    vector<Sequence> spacers;
    l->get_spacers(spacers);
    cout << "spacer count:  " << spacers.size() << endl;


    if (l->get_check_contigs())
    {
        cout << "investigating spacer-contig connections" << endl;

        //get contigs
        vector<Sequence> virus_contigs;
        l->get_virus_contigs(virus_contigs);
        cout << "contig count:  " << virus_contigs.size() << endl;

        //find exact kmer matches
        cout << "finding exact matches of size k" << endl;
        vector<Match> spacer_contig;
        s->get_matches(spacer_contig, spacers, virus_contigs);
        cout << "nummber of matching k-mers:  " << spacer_contig.size() << endl;

        //extend matches and keep if identify abover certain threshold
        cout << "extending identified matches" << endl;
        vector<Assoc> spacer_contig_a;
        n->get_assocs(spacer_contig_a, spacer_contig);
        cout << "number of matching sequences above given identity:  " << spacer_contig_a.size() << endl;
        spacer_contig.clear();

        //analyze results
        cout << "analyzing resulting signficant matches" << endl;
        string results = l->get_results()+"_results_c.txt";
        a -> print_results(spacer_contig_a, results.c_str());
        results = l->get_results()+"_edges_c.txt";
        a -> make_cytoscape(spacer_contig_a, results.c_str());
        results = l->get_results()+"_PAMs_c.txt";
        a -> find_PAMs(spacer_contig_a, results.c_str());
    }

    //repeat analysis comparing spacers to known genomes
    if (l->get_check_genomes())
    {
        cout << "investigating spacer-genome connections" << endl;

        //get genomes
        vector<Sequence> virus_genomes;
        l->get_virus_genomes(virus_genomes);
        cout << "genome count:  " << virus_genomes.size() << endl;

        //get kmer matches
        cout << "finding exact matches of size k" << endl;
        vector<Match> spacer_genome;
        s->get_matches(spacer_genome, spacers, virus_genomes);
        cout << "number of matching k-mers:  " << spacer_genome.size();

        //get extend matches and save significants
        cout << "extending identified matches" << endl;
        vector<Assoc> spacer_genome_a;
        n->get_assocs(spacer_genome_a, spacer_genome);
        cout << "number of matching sequences above given identity:  " << spacer_genome_a.size() << endl;
        spacer_genome.clear();

        //analyze results
        cout << "analyzing resulting signficant matches" << endl;
        string results = l->get_results()+"_results_g.txt";
        a -> print_results(spacer_genome_a, results.c_str());
        results = l->get_results()+"_edges_g.txt";
        a -> make_cytoscape(spacer_genome_a, results.c_str());
        results = l->get_results()+"_PAMs_g.txt";
        a -> find_PAMs(spacer_genome_a, results.c_str());
    }

    delete l;
    delete s;
    delete n;
    delete a;

    return 0;
}

vector<string> CLI()
{

}
